package ru.xeden.web.html.component.lib;

import java.io.PrintWriter;

import ru.xeden.web.html.RenderContext;
import ru.xeden.web.html.component.IComponent;
import ru.xeden.web.html.dom.MarkupModel;
import ru.xeden.web.html.dom.Node;


/**
 * Ссылка
 * @author evga
 */
public class Link
    extends Node
    implements IComponent
{
    private String text;
    private String url;

    public Link()
    {
    }

    public Link(String text, String url)
    {
        setText(text);
        setUrl(url);
    }

    public String getText()
    {
        return text;
    }

    public void setText(String text)
    {
        this.text = text;
    }

    public String getUrl()
    {
        return url;
    }

    public void setUrl(String url)
    {
        this.url = url;
    }

    @Override
    public void toMarkup(RenderContext markupContext, PrintWriter writer)
    {
        MarkupModel markupModel = markupContext.getMarkupModel();
        writer.print("<a href=");
        writer.print(markupModel.getAttributeQuote());
        writer.print(markupContext.getRequest().getServletPath());
        writer.print(url);
        writer.print(markupModel.getAttributeQuote());
        writer.print(">");
        writer.print(markupContext.getMarkupModel().encode(text));
        writer.print("</a>");
    }
}
